<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>组件中事件的定义</title>
  </head>
  <body>
    <div id="app">
      <login></login>
    </div>
    <template id="test">
      <div>
        <input type="button" value="点我触发组件中的事件" @click="change" />
      </div>
    </template>
  </body>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    const login = {
      template: "#test",
      data() {
        return {
          name: "小黑",
        };
      },
      methods: {
        change() {
          alert("触发事件" + this.name);
        },
      },
    };
    const app = new Vue({
      el: "#app",
      data: {},
      methods: {},
      components: {
        login,
      },
    });
  </script>
</html>
